﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;


public partial class MasterPages_Default : System.Web.UI.Page
{
	protected void mvAbonneren_ActiveViewChanged(object sender, EventArgs e)
	{

	}

	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			//Fill Years
			for (int i = 1900; i <= DateTime.Now.Year; i++)
			{
				ddlYear.Items.Add(i.ToString());
			}
			ddlYear.Items.FindByValue(System.DateTime.Now.Year.ToString()).Selected = true;  //set current year as selected

			//Fill Months
			for (int i = 1; i <= 12; i++)
			{
				ddlMonth.Items.Add(i.ToString());
			}
			ddlMonth.Items.FindByValue(System.DateTime.Now.Month.ToString()).Selected = true; // Set current month as selected

			//Fill days
			FillDays();
		}
	}
	public void FillDays()
	{
		ddlDay.Items.Clear();
		//getting numbner of days in selected month & year
		int noofdays = DateTime.DaysInMonth(Convert.ToInt32(ddlYear.SelectedValue), Convert.ToInt32(ddlMonth.SelectedValue));

		//Fill days
		for (int i = 1; i <= noofdays; i++)
		{
			ddlDay.Items.Add(i.ToString());
		}
		ddlDay.Items.FindByValue(System.DateTime.Now.Day.ToString()).Selected = true;// Set current date as selected
	}

	protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
	{
		FillDays();
	}

	protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
	{
		FillDays();
	}
	protected void btnVerder_Click(object sender, EventArgs e)
	{

		try
		{
			if (Roles.RoleExists("Abonnee"))
			{
				

				if (Membership.GetUser(txtGebruikersnaam.Text) != null)
				{
					lblError.Text = "Gebruikersnaam bestaat al.";
				}
				else
				{
					MembershipUser newUser = Membership.CreateUser(txtGebruikersnaam.Text, txtWachtwoord2.Text, txtEmailadres2.Text);
					Roles.AddUserToRole(txtGebruikersnaam.Text, "Abonnee");
					mvAbonneren.ActiveViewIndex = 1;
				}

			}

		}
		catch (Exception ex)
		{
			txtGebruikersnaam.Text = ex.Message;
		}
	}


	protected void btnBevestig_Click(object sender, EventArgs e)
	{
		mvAbonneren.ActiveViewIndex = 2;
	}
}
